<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>会员管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="icon" href="/images/favicon.ico">
    <link rel="stylesheet" href="/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <fieldset class="table-search-fieldset">
            <legend>搜索信息</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" action="">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">关键字</label>
                            <div class="layui-input-inline">
                                <label for="keyword"></label>
                                <input id="keyword" type="text" name="keyword" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">是否冻结</label>
                            <div class="layui-input-inline">
                                <select id="startOrStop">
                                    <option value="">全部</option>
                                    <option value="0">未冻结</option>
                                    <option value="1">已冻结</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button id="searchBtn" type="button"
                                    class="layui-btn layui-btn-primary" lay-submit
                                    lay-filter="data-search-btn">
                                <i class="layui-icon"></i> 搜 索
                            </button>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-xs layui-btn-radius layui-btn-normal data-count-delete"
               lay-event="start">解冻</a>
            <a class="layui-btn layui-btn-xs layui-btn-radius layui-btn-danger data-count-delete"
               lay-event="stop">冻结</a>
        </script>

    </div>
</div>
<script src="/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="/js/lay-config.js" charset="utf-8"></script>
<script th:inline="none">
    layui.use(['form', 'dropdown', 'table', 'layer', 'upload', 'common'], function () {
        let $ = layui.jquery,
            dropdown = layui.dropdown,
            form = layui.form,
            table = layui.table,
            layer = layui.layer,
            upload = layui.upload;

        // 搜索按钮绑定事件
        $("#searchBtn").on("click", function () {
            // table表格渲染数据
            table.render({
                elem: '#currentTableId',
                url: '/member/list', // 发送请求的地址
                where: {
                    keyword: $("#keyword").val(),
                    status: $("#startOrStop").val()
                },
                cols: [[
                    {field: 'code', title: '会员ID', width: 332, style: 'color: blue;'},
                    {field: 'username', title: '账号', style: 'color: Lime;'},
                    {field: 'nickname', title: '昵称', style: 'color: Teal;'},
                    {field: 'sex', title: '性别', style: 'color: darkturquoise;'},
                    {field: 'freezeAndThaw', title: '是否被冻结', sort: true, style: 'color: deeppink;'},
                    {title: '操作', toolbar: '#currentTableBar', align: "center", width: 189}
                ]],
                limits: [10, 15, 20, 25, 50, 100],
                limit: 10,
                page: true,
                skin: 'line'
            }); //end table.render
        }).click(); //end $("#searchBtn")


        // 表格操作工具条时间
        table.on('tool(currentTableFilter)', function (obj) {

            if (obj.event === 'start') { // 点的是启用
                layer.confirm("确认解冻该会员吗？", function () {
                    $.post("/member/start/" + obj.data.id, function () {
                        layer.msg("该会员已被解冻！", {
                            icon: 1,
                            time: 1200
                        });
                        $("#searchBtn").click();
                    }); //end post
                }); //end confirm
            } // end if

            if (obj.event === 'stop') { // 点的是停用
                layer.confirm("确认冻结该会员吗？", function () {
                    $.post("/member/stop/" + obj.data.id, function () {
                        layer.msg("该会员已被冻结！", {
                            icon: 1,
                            time: 1200
                        });
                        $("#searchBtn").click();
                    }); //end post
                }); //end confirm
            } // end if

        }); //end tool(currentTableFilter)

    }); //end layui.use
</script>

</body>
</html>